(function($) { "use strict";
	var textHolder = document.getElementsByClassName('big-text-neon')[0],
	  text = textHolder.innerHTML,
		chars = text.length,
		newText = '',
		i;	

	for (i = 0; i < chars; i += 1) {
		newText += '<i>' + text.charAt(i) + '</i>';
	}

	textHolder.innerHTML = newText;

	var letters = document.getElementsByTagName('i'),
		flickers = [5, 7, 9, 11, 13, 15, 17],
		randomLetter,
		flickerNumber,
		counter;

	function randomFromInterval(from,to) {
		return Math.floor(Math.random()*(to-from+1)+from);
	}

	function hasClass(element, cls) {
		return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
	}

	function flicker() {		
		counter += 1;
		
		if (counter === flickerNumber) {
			return;
		}

		setTimeout(function () {
			if(hasClass(randomLetter, 'off')) {
				randomLetter.className = '';
			}
			else {
				randomLetter.className = 'off';
			}

			flicker();
		}, 30);
	}

	(function loop() {
		var rand = randomFromInterval(300,1200);

		randomLetter = randomFromInterval(0, 6);
		randomLetter = letters[randomLetter];
		
		flickerNumber = randomFromInterval(0, 3);
		flickerNumber = flickers[flickerNumber];

		setTimeout(function() {
				counter = 0;
				flicker();
				loop();  
		}, rand);
	}());
})(jQuery);